﻿Imports DevComponents.DotNetBar
Imports System.Data.SqlClient

Public Class frmNuevoPedido

    Dim variableconex As New SqlConnection(My.Settings.CITRA_ERPConnectionString)

    Private Sub frmNuevoPedido_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SlidePanel1.IsOpen = False
        SlidePanel2.IsOpen = False
        SlidePanel3.IsOpen = False
        SlidePanel5.IsOpen = False
        SlidePanel5.BackColor = Color.Black


    End Sub

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles ButtonX1.Click
        Close()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonX2_Click(sender As Object, e As EventArgs) Handles ButtonX5.Click
        frmProductosPedidos.ShowDialog()
    End Sub

    Private Sub ButtonX3_Click(sender As Object, e As EventArgs) Handles ButtonX3.Click

        Modificar()

    End Sub

    Public Sub Modificar()

        Try

            Dim Mensaje, Titulo, ValorDefault As String
            Dim CantidadProducto As Object

            Dim fila As Integer
            fila = dgvProductosPedido.CurrentCell.RowIndex

            Dim valor As String
            Dim valor2 As String
            Dim valor3 As String
            valor = dgvProductosPedido.Rows(fila).Cells(0).Value.ToString()
            valor2 = dgvProductosPedido.Rows(fila).Cells(1).Value.ToString()
            valor3 = dgvProductosPedido.Rows(fila).Cells(2).Value.ToString()

            ValorDefault = dgvProductosPedido.Rows(fila).Cells(3).Value.ToString()

            Mensaje = "Cantidad que queres solicitar ya sea en unidades o litros"
            Titulo = "Solicitar Cantidad"
            CantidadProducto = InputBox(Mensaje, Titulo, ValorDefault)
            If CantidadProducto Is "" Then CantidadProducto = ValorDefault



            If CantidadProducto = 0 Then


            Else

                dgvProductosPedido.Rows.Remove(dgvProductosPedido.Rows(fila))

                Dim row1() As String = {valor, valor2, valor3, CantidadProducto.ToString}

                dgvProductosPedido.Rows.Add(row1)

                ToastNotification.Show(Me, "Modificado correctamente", My.Resources.checkHommer, 3000, eToastGlowColor.Blue, eToastPosition.MiddleCenter)

            End If

        Catch ex As Exception
            ToastNotification.Show(Me, "No hay elementos para editar....!", My.Resources.cancelHommer, 3000, eToastGlowColor.Blue, eToastPosition.MiddleCenter)
        End Try

    End Sub

    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles ButtonX4.Click

        Quitar()

    End Sub

    Public Sub Quitar()

        Try

            Dim fila As Integer
            fila = dgvProductosPedido.CurrentCell.RowIndex
            dgvProductosPedido.Rows.Remove(dgvProductosPedido.Rows(fila))
            ToastNotification.Show(Me, "Eliminado correctamente", My.Resources.checkHommer, 3000, eToastGlowColor.Blue, eToastPosition.MiddleCenter)


        Catch ex As Exception

            ToastNotification.Show(Me, "No hay elementos para eliminar....!", My.Resources.cancelHommer, 3000, eToastGlowColor.Blue, eToastPosition.MiddleCenter)

        End Try

    End Sub

    Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
        SolicitarPedido()
    End Sub

    Public Sub SolicitarPedido()

        Dim productos As New ArrayList(10)

        Dim i As Integer = 0

        While i < Me.dgvProductosPedido.Rows.Count

            productos.Add(dgvProductosPedido.Rows(i).Cells(0).Value.ToString())

            i = i + 1

        End While

        For Each miVariable As String In productos

            calcularProveedor(miVariable)

        Next


    End Sub

    Public Sub calcularProveedor(producto As Integer)


        Dim DA As New SqlDataAdapter("SELECT TOP 3 IDPROVEEDOR,(TIEMPO_ENTREGA)*(-1)+(PRECIO)*(-1)+GARANTIA AS TOTAL FROM Productos_Proveedor  WHERE IDPRODUCTO=" & producto & " ORDER BY TOTAL DESC;", variableconex)
        Dim dt As New DataTable

        Dim ArrayNombres As New ArrayList
        DA.Fill(dt)

        For Each dr As DataRow In dt.Rows
            ArrayNombres.Add(dr(0).ToString())
        Next

        Dim i As Integer = 0
        Dim j As Integer

        For Each miVariable As String In ArrayNombres
            i = i + 1
        Next

        For j = 1 To i
            MsgBox(ArrayNombres(j - 1))
        Next

    End Sub

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub btnMostrarOpciones_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonItem24_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonItem23_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonItem17_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonItem12_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub btnNuevo_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub btnCerrar_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub ButtonItem40_Click(sender As Object, e As EventArgs) Handles ButtonItem40.Click
        SolicitarPedido()
    End Sub

    Private Sub ButtonItem22_Click(sender As Object, e As EventArgs)
        SlidePanel1.IsOpen = True
    End Sub

    Private Sub ButtonItem21_Click(sender As Object, e As EventArgs) Handles ButtonItem21.Click
        SlidePanel1.IsOpen = False
    End Sub

    Private Sub ButtonItem43_Click(sender As Object, e As EventArgs) Handles ButtonItem43.Click
        SlidePanel2.IsOpen = False
    End Sub

    Private Sub ButtonItem66_Click(sender As Object, e As EventArgs) Handles ButtonItem66.Click
        SlidePanel2.IsOpen = True
    End Sub

    Private Sub ButtonItem70_Click(sender As Object, e As EventArgs) Handles ButtonItem70.Click
        SlidePanel3.IsOpen = True
    End Sub

    Private Sub ButtonItem44_Click(sender As Object, e As EventArgs) Handles ButtonItem44.Click
        SlidePanel3.IsOpen = False
    End Sub

    Private Sub ButtonItem19_Click(sender As Object, e As EventArgs) Handles ButtonItem19.Click
        SlidePanel5.IsOpen = False
    End Sub

    Private Sub ButtonItem57_Click(sender As Object, e As EventArgs) Handles ButtonItem57.Click
        SlidePanel5.IsOpen = True
    End Sub

    Private Sub ButtonItem22_Click_1(sender As Object, e As EventArgs) Handles ButtonItem22.Click
        SlidePanel1.IsOpen = True
    End Sub

    Private Sub ButtonItem34_Click(sender As Object, e As EventArgs) Handles ButtonItem34.Click
        SlidePanel2.IsOpen = True
    End Sub

    Private Sub ButtonItem38_Click(sender As Object, e As EventArgs) Handles ButtonItem38.Click
        SlidePanel3.IsOpen = True
    End Sub
End Class